a.SetPrintFunc(PrintStudent); 
    

    void PrintStudent(void *studentPtr)
{
    Student *student = static_cast<Student *>(studentPtr);
    if (student)
        student->print(); // 调用 Student 的 print 方法
}
在main函数中，


void DynamicArray::SetPrintFunc(void (*Print)(ElementType))
{
    this->Print = Print;
}


    void SetPrintFunc(void (*Print)(ElementType));


    void DynamicArray ::show()
{
    for (size_t i = 0; i < size; i++)
        if (Print)
            Print(array[i]);
        else
            std::cout << array[i] << " ";
    std::cout << std::endl;
}
DynamicArray。cpp